use ftlog::appender::{file::Period, FileAppender};
use ftlog::{debug, trace};
use log::LevelFilter;
use log::{error, info, warn};
//use std::io::stdin;
use time::Duration;

fn init() {
    // Rotate every day, clean stale logs that were modified 7 days ago on each rotation
    let writer = FileAppender::rotate_with_expire("./current.log", Period::Day, Duration::weeks(1));
    let builder = ftlog::Builder::new()
        // global max log level
        .max_log_level(LevelFilter::Trace)
        // define root appender, pass None would write to stderr
        .root(writer)
        // write logs in ftlog::appender to "./ftlog-appender.log" instead of "./current.log"
        .filter("ftlog::appender", "ftlog-appender", LevelFilter::Trace)
        .appender("ftlog-appender", FileAppender::new("ftlog-appender.log"));
    builder.try_init().expect("logger build or set failed");
}

// fn press_any_key_to_continue() {
//     let mut input = String::new();
//     stdin().read_line(&mut input).unwrap();
// }

fn finish() {
    log::logger().flush();
}

fn main() {
    init();

    trace!("Hello world!");
    debug!("Hello world!");
    info!("Hello world!");
    warn!("Hello world!");
    error!("Hello world!");

    //press_any_key_to_continue();

    finish();
}
